package get.newsdaily;

import get.newsdaily.adapters.NewsAdapter;
import get.newsdaily.model.RssItem;
import get.newsdaily.utils.variables;

import java.util.List;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

public class NewsListActivity extends ListActivity {
	private List<RssItem> items;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Bundle bundle = getIntent().getExtras(); //get intent đã định nghĩa
		
		int category = bundle.getInt(variables.CATEGORY);
		int paper = bundle.getInt(variables.PAPER);
		
		setTitle(variables.PAPERS[paper] + " - "+ variables.CATEGORIES[paper][category]);
		
		int key = paper * 1000 + category;
		items = variables.newsmap.get(key);
		
		NewsAdapter adapter = new NewsAdapter(this, R.layout.news, items, paper);
		setListAdapter(adapter);
		
		
		
		
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		// TODO Auto-generated method stub
		super.onListItemClick(l, v, position, id);
		
		Intent intent = new Intent(NewsListActivity.this, NewsActivity.class);
		intent.putExtra(variables.LINK, items.get(position).getLink()); //Trả về RSS
		startActivity(intent);
		
	}
	

}
